﻿using OF.Component.Base;
using OF.Component.BLL;
using OF.Component.DTO;
using OF.Component.Model;
using OF.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OP.manage.post
{
    public partial class sendlist : OpBasePage
    {
        protected int intCount = 0;
        protected int intPageIndex = 1;
        protected string style = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            SetPageCode(102, 10202);
            if (!IsPostBack)
            {
                setBind();
                MyBind();
            }
            if (IsSessionPostBack)
            {
                setBind();
            }
        }

        private void setBind()
        {
            BindLocation(ref this.ddlLocation, 0, 0);
        }

        protected void ddlLocation_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindLocation(ref this.ddlcity, EConvert.ToInt(this.ddlLocation.SelectedValue), 1);

        }

        void MyBind()
        {
            var pageIndex = pager1.CurrentPageIndex;
            //获取搜索条件
            var condition = new scPostSend();

            condition.Mobile = this.txtMobile.Text; ;
            condition.CreateStartDate = txtStartDate.Text;
            condition.CreateEndDate = txtEndDate.Text;
            condition.LocationId = this.ddlcity.SelectedValue == "" ? 0 : int.Parse(this.ddlcity.SelectedValue);
            condition.PageIndex = pageIndex;
            condition.PageSize = pager1.PageSize;
            condition.ProvinceId = this.ddlLocation.SelectedValue == "" ? 0 : int.Parse(this.ddlLocation.SelectedValue);

            var list = PostSendOperate.SearchList(condition);
            //删除后当前分页没有数据的情况，则页数-1再次获取数据
            if (list.Count == 0 && pageIndex > 1)
            {
                condition.PageIndex--;
                list = PostSendOperate.SearchList(condition);
            }
            rptDataList.DataSource = list;
            rptDataList.DataBind();

            if (condition.TotalRecord > 0)
            {
                style = "style=\"display:none\"";
            }
            pager1.RecordCount = condition.TotalRecord;

        }



        /// <summary>
        /// 搜索事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            pager1.CurrentPageIndex = 1;
            MyBind();
        }
        #region 翻页事件
        /// <summary>
        /// 翻页事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void pager1_PageChanged(object sender, EventArgs e)
        {
            MyBind();
        }
        #endregion

        public string GetBizTypeNameById(int id)
        {
            string name = "";
            BizTypeInfo info = BizTypeOperate.QuerySingle(a => a.BizTypeID == id);
            if (info != null)
            {
                name = info.BizTypeName;
            }
            return name;

        }
    }
}